package com.boge.modules.house.service.impl;

import com.boge.modules.house.entity.THouseEntity;
import com.boge.modules.house.service.THouseService;
import com.boge.modules.sys.controller.WebController;
import com.boge.modules.sys.entity.SysUserEntity;
import com.boge.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.Query;

import com.boge.modules.house.dao.TLeaseDao;
import com.boge.modules.house.entity.TLeaseEntity;
import com.boge.modules.house.service.TLeaseService;


@Service("tLeaseService")
public class TLeaseServiceImpl extends ServiceImpl<TLeaseDao, TLeaseEntity> implements TLeaseService {

    @Autowired
    private SysUserService userService;

    @Autowired
    private THouseService houseService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TLeaseEntity> page = this.page(
                new Query<TLeaseEntity>().getPage(params),
                new QueryWrapper<TLeaseEntity>()
        );
        List<TLeaseEntity> records = page.getRecords();
        if(records != null){
            for (TLeaseEntity record : records) {
                Integer userId = record.getUserId();
                SysUserEntity userEntity = userService.getById(userId);
                record.setUserName(userEntity.getNickname());
                Integer houseId = record.getHouseId();
                THouseEntity houseEntity = houseService.getById(houseId);
                record.setHouseName(houseEntity.getName());
                record.setHouseImg(WebController.BASE_URL+houseEntity.getImg());
            }
        }
        return new PageUtils(page);
    }

}